# Maintainer: Alexey Yerin <yyp@disroot.org>
pkgname=haskell-language-server
pkgver=2.9.0.0
pkgrel=0
pkgdesc="Official Haskell Language Server implementation"
url="https://github.com/haskell/haskell-language-server"
arch="x86_64 aarch64" # limited by ghc
license="Apache-2.0"
makedepends="ghc cabal zlib-dev"
source="https://hackage.haskell.org/package/haskell-language-server-$pkgver/haskell-language-server-$pkgver.tar.gz
	cabal.project.freeze"
options="!check" # Tests fail

export CABAL_DIR="$srcdir/cabal"
export PATH="$PATH:/usr/lib/llvm15/bin"

cabal_update() {
	cd $builddir
	rm cabal.project.freeze
	cabal v2-update
	(
		cabal v2-freeze \
			--shadow-installed-packages \
			--disable-benchmarks \
			--flags "-dynamic"
		mv cabal.project.freeze "$startdir/"
	)
}

prepare() {
	default_prepare
	ln -sf "$srcdir/cabal.project.freeze" \
		"$builddir/cabal.project.freeze"

	cabal v2-update
	cabal v2-build \
		--only-download \
		--disable-benchmarks \
		--flags "-dynamic"
}

check() {
	cabal test
}

build() {
	cabal v2-build haskell-language-server:exes \
		--jobs=${JOBS:-1} \
		--prefix=/usr \
		--disable-benchmarks \
		--flags "-dynamic" \
		--enable-relocatable
}

package() {
	for exe in haskell-language-server haskell-language-server-wrapper; do
		install -Dm755 "$(cabal list-bin $exe)" "$pkgdir"/usr/bin/$exe
	done
}

sha512sums="
ecf5a5d895eff1e8d383c4b6870d91b094f2d77b4b695caadb97935a280a558fea0d133935edb0811edeb60a4e5bc646a0290181002c86675f4c1d1ca335b5ab  haskell-language-server-2.9.0.0.tar.gz
0b49931fecadb3591cd2591daea96a85dc13c556b2ed791a162ae045d563b06efe182a6b99fde892faa4fcb47a2142b2517deff394a3409a4c286881ac3df488  cabal.project.freeze
"
